#ifndef L2_CONFIGURATOR_HPP
#define L2_CONFIGURATOR_HPP

#include "L2DataSet.hpp"

#define PORT_MAX_LINE_LENGTH 64

class Configurator : public DataSet {
public:
    class FileAdapter {
    public:
        enum Flag {
            Flag_Read,
            Flag_Write,
        };
    public:
        virtual bool open(int flag) = 0;
        virtual bool close() = 0;
        virtual unsigned int readline(void *buffer) = 0;
        virtual unsigned int writeline(void *buffer) = 0;
    };

    enum ErrorNumber {
        Error_NoFileAdapter = 11,
        Error_NoDataSet,
        Error_FileOpenFailed,
        Error_FileCloseFailed,
        Error_FileWriteError,
    };
public:
    explicit Configurator(DataSet *dataset,FileAdapter *file_adapter);
    virtual ~Configurator();

    virtual bool add(const char *label,bool value);
    virtual bool add(const char *label,double value);
    virtual bool add(const char *label,const char *value);
    virtual bool remove(const char *label);
    virtual bool set(const char *label,bool value);
    virtual bool set(const char *label,double value);
    virtual bool set(const char *label,const char *value);
    virtual bool getBoolean(const char *label);
    virtual double getNumber(const char *label);
    virtual const char *getString(const char *label);
    virtual bool hasLabel(const char *label);
    virtual DataType getDataType(const char *label);

    virtual bool clear(void);
    virtual int getDataCount(void);
    virtual struct Data *getDataItem(int pos);

    virtual bool load(void);
    virtual bool store(void);
    virtual bool storeModified(void);
public:
    static const char *str_TRUE;
    static const char *str_FALSE;
protected:
    DataSet *dataset;
    FileAdapter *file_adapter;
    bool modify_flag = false;
};

#endif
